package com.chinasoft.app.action;

import org.apache.struts2.ServletActionContext;

import com.chinasoft.app.domain.Customer;
import com.chinasoft.app.domain.Messagebox;
import com.chinasoft.app.service.MessageService;
import com.chinasoft.app.vo.MessagePage;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class MessageAction extends ActionSupport implements ModelDriven<Messagebox>{
	private Messagebox messagebox=new Messagebox();
	private Customer customer=new Customer();
	private MessageService messageservice;
	int currentpage=1;
	int pagesize=10;

	
	public Messagebox getMessagebox() {
		return messagebox;
	}

	public void setMessagebox(Messagebox messagebox) {
		this.messagebox = messagebox;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public int getCurrentpage() {
		return currentpage;
	}

	public void setCurrentpage(int currentpage) {
		this.currentpage = currentpage;
	}

	public int getPagesize() {
		return pagesize;
	}

	public void setPagesize(int pagesize) {
		this.pagesize = pagesize;
	}

	public void setMessageservice(MessageService messageservice) {
		this.messageservice = messageservice;
	}
	
	public String messAdd(){
		messageservice.MessAdd(messagebox);
		return "add_mess_success";
	}
	public String messUpdate(){
		messageservice.MessUpdate(messagebox);
		return "update_mess_success";
	}
	public String messDelete(){
		messageservice.MessDelete(messagebox.getMsgId());
		return "delete_mess_success";
	}
	public String searchByUsername(){
		MessagePage messagepage=messageservice.MessSearchByUser(customer.getUsername(), currentpage, pagesize);
		ServletActionContext.getRequest().setAttribute("messagepage",messagepage);
		return "search_success";
	}


	@Override
	public Messagebox getModel() {
		// TODO Auto-generated method stub
		return messagebox;
	}

}
